<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2017/8/26
 * Time: 20:04
 */
namespace app\admin\controller\active;

use app\admin\model\StaffCard;
use app\common\controller\Backend;
use app\common\model\Category as CategoryModel;

class Index extends Backend{
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('active');
    }

    /**
     * 活动列表展示，并可以通过此页面发布活动，也可以修改相应的活动属性
     */
    public function index()
    {
        /**
         * 如果为ajax提交，则返回相应json数据
         */
        if ($this->request->isAjax())
        {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model
                ->where($where)
                ->order($sort, $order)
                ->count();
            $list = $this->model
                ->where($where)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();
            $result = array("total" => $total, "rows" => $list);
            return json($result);
        }
        return $this->view->fetch();
    }
}